package com.vfd.collections.iterartors {
	import com.vfd.collections.iterartors.IIterator;
	
	/**
	* Basic iteration class.
	* @author Jeremy Wischusen <cortex@visualflowdesigns.com>
	*/
	public class Iterator implements IIterator {
		protected var _items:Object; 
		protected var _loop:Boolean = false; 
		protected var _index:Number = 0;
		public function Iterator(items:Object, loop:Boolean = false):void {
			this._items = items; 
			this._loop = loop;
		}
		
		public function next():Object{
		this._index++; 
		return this.getItem();
	}
	public function prev():Object {
		this._index--;
		return this.getItem();
	}
	protected function getItem():Object {
		this.constrainIndex();
		return this._items[this._index];
	}
	protected function constrainIndex():void {
		
			if(this._loop)
		{
			if(this._index < 0)
			{
				this._index = this._items.length - 1;
			}
			else if(this._index >= this._items.length)
			{
				this._index = 0;
			}
		}
		else
		{
			if(this._index < 0)
			{
				this._index = 0;
			}
			else if(this._index >= this._items.length)
			{
				this._index = this._items.length - 1;
			}
		}
		
	}
	
	}
}